<?php

namespace App\Http\Controllers\Admin;

use App\Services\Admin\RoleService;

class ComboController extends AdminBaseController
{
    protected $roleService;

    public function __construct(RoleService $roleService)
    {
        $this->roleService = $roleService;
    }

    /**
     * 获取模块下拉框数据
     * @return \Illuminate\Http\JsonResponse
     */
    public function modules(): \Illuminate\Http\JsonResponse
    {
        $modules = config('modules', []);
        $data = [];

        foreach ($modules as $key => $value) {
            $data[] = [
                'value' => $key,
                'label' => $value
            ];
        }

        return $this->success($data);
    }

    /**
     * 获取角色下拉框数据
     * @return \Illuminate\Http\JsonResponse
     */
    public function roles(): \Illuminate\Http\JsonResponse
    {
        $roles = $this->roleService->all();
        $data = [];

        foreach ($roles as $role) {
            $data[] = [
                'value' => (string) $role['id'],
                'label' => $role['name']
            ];
        }

        return $this->success($data);
    }
}
